import { Table, Button, Space, Divider } from 'ant-design-vue';
import { uploadFile } from '@/api/common.api'
const { VITE_FILE_URL } = import.meta.env;

export const tableSchemas: any[] = [

  {
    title: '服务名称',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
    width: 160,
    inSearch: true
  },
  {
    title: '子名称',
    dataIndex: 'subName',
    key: 'subName',
    align: 'center',
    width: 160,
    inSearch: true
  },
  {
    title: '图标',
    dataIndex: 'iconUrl',
    key: 'iconUrl',
    align: 'center',
    width: 80,
    customRender({ text, record, index, column }) {
      return <a-image
        preview={false}
        width={50}
        height={50}
        src={`${VITE_FILE_URL}${text}`}
      />

    }
  },
  {
    title: '价格（元）',
    dataIndex: 'price',
    key: 'price',
    align: 'center',
    width: 100,
  },
  {
    title: '优惠价格（元）',
    dataIndex: 'discountPrice',
    key: 'discountPrice',
    align: 'center',
    width: 140,

  },
  {
    title: '简介',
    dataIndex: 'summary',
    key: 'summary',
    align: 'left',
    width: 240,
  },
  {
    title: '服务内容',
    dataIndex: 'content',
    key: 'content',
    align: 'left',

  },
  {
    title: '状态',
    dataIndex: 'status',
    key: 'status',
    align: 'center',
    width: 80,
    inSearch: true,
    customRender({ text, record, index, column }) {
      return text?.status;
    }
  },

];

export const formSchemas: any[] = [
  {
    component: 'Input',
    label: 'ID',
    name: 'id',
    dataIndex: 'id',
    vShow: false,
  },
  {
    component: 'Input',
    label: '服务名称',
    dataIndex: 'name',
    name: 'name',

  },
  {
    component: 'Input',
    label: '子名称',
    dataIndex: 'subName',
    name: 'subName',
  },


  {
    component: 'Upload',
    label: '图标',
    dataIndex: 'iconUrl',
    name: 'iconUrl',
    componentProps: {
      maxCount: 1,
      showUploadList: false,
      listType: "picture-card",

      bindCustomRequest(formState, { file }) {
        const formData = new FormData();
        formData.append('file', file);
        uploadFile(formData).then(({ path }) => {
          formState.iconUrl = path
        })
      }
    }
  },
  {
    component: 'InputNumber',
    label: '价格（元）',
    dataIndex: 'price',
    name: 'price',

  },
  {
    component: 'InputNumber',
    label: '优惠价（元）',
    dataIndex: 'discountPrice',
    name: 'discountPrice',

  },
  {
    component: 'InputTextArea',
    label: '简介',
    dataIndex: 'summary',
    name: 'summary',

  },
  {
    component: 'InputTextArea',
    label: '服务内容',
    dataIndex: 'content',
    name: 'content',

  },
  {
    component: 'RadioGroup',
    label: '状态',
    dataIndex: 'status',
    name: 'status',
    width: 80,
    componentProps: {
      optionType: 'button',
      options: [{ label: '下架', value: 0 }, { label: '上架', value: 1 }]
    }
  },
];
